﻿using System.Text;

using System.ComponentModel.DataAnnotations;


using System;
using System.Collections.Generic;

using System.Linq;
using Wedo.Mvc.Utility;
using Wedo.Domain.Models;
using System.ComponentModel;

namespace Wedo.Recognition.Domain.Models
{
    /// <summary>
    /// 认款申请信息
    /// </summary>
    [System.ComponentModel.DisplayName("认款申请信息")]
    public class PaymentApply : Entity
    {

        /// <summary>
        /// 账单数据编号
        /// </summary>
        public Guid BankDataId { set; get; }

        public BankData BankData { get; set; }

        #region 认款信息
        /// <summary>
        /// 客户编号
        /// </summary>        
        [Required(ErrorMessage = "{0} 不能为空！")]
        [DisplayName( "客户编号")]
        public string CustomerCode { set; get; }

        /// <summary>
        /// 客户名称
        /// </summary>
        [DisplayName( "客户名称")]
        [Required(ErrorMessage = "{0} 不能为空！")]
        public string CustomerName { set; get; }

        /// <summary>
        /// 手续费
        /// </summary>
        [DisplayName( "手续费")]
        public decimal? Fee { get; set; }

        /// <summary>
        /// 订单编号
        /// </summary>
        //[DataColumn(30, 100)]
        [DisplayName( "订单编号")]
        [RegularExpression(@"[0-9]*", ErrorMessage = "订单编号必须为数字")]
        [Required(ErrorMessage = "{0} 不能为空！")]
        public string OrderNum { set; get; }

        /// <summary>
        /// 认款金额
        /// </summary>
        [DisplayName( "认款金额")]
        [Required(ErrorMessage = "{0} 不能为空！")]
        public decimal Amount { set; get; }

        /// <summary>
        /// 所占比例
        /// </summary>
        [DisplayName( "所占订单总额比例")]
        //[DataColumn(50, 100)]
        public decimal? Percent { set; get; }

        /// <summary>
        /// 是否为预付款
        /// </summary>
        [DisplayName( "预付款")]
        public bool? AdvancePayment { set; get; }

        /// <summary>
        /// 是否需要放单
        /// </summary>
        [DisplayName( "是否需要放单")]
        public string ReleaseOrder { set; get; }

        /// <summary>
        /// SAP Billing
        /// </summary>
        //[DataColumn(72, 100)]
        [DisplayName( "SAP Billing")]
        public string BillingNo { set; get; }
        /// <summary>
        /// 合同编号
        /// </summary>
        //[DataColumn(73, 100)]
        [DisplayName( "合同编号")]
        public string ContractNo { set; get; }
        /// <summary>
        /// 部门
        /// </summary>
        //[DataColumn(74, 100)]
        [DisplayName( "部门")]
        public string Division { set; get; }

        /// <summary>
        /// 备注
        /// </summary>
        [DisplayName( "备注")]
        public string Note { get; set; }

        /// <summary>
        /// 附件信息
        /// </summary>
        public virtual List<PaymentAttach> PaymentAttachs { get; set; }
        #endregion

        #region 审核

        /// <summary>
        /// 申请人
        /// </summary>
        [DisplayName( "申请人")]
        //[DataColumn(60, 60)]
        public string ApplyMan { set; get; }

        /// <summary>
        ///申请时间
        /// </summary>
        [DisplayName( "申请时间")]
        //[DataColumn(70, 60)]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
        public DateTime? ApplyTime { set; get; }

        /// <summary>
        /// 审批人
        /// </summary>
        [DisplayName( "审批人")]
        ////[DataColumn(80, 60)]
        public string Approver { set; get; }

        /// <summary>
        ///  审批时间
        /// </summary>
        [DisplayName( "审批时间")]
        ////[DataColumn(90, 60)]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
        public DateTime? ApprovalTime { set; get; }

        /// <summary>
        /// 状态 1 等待审批 2 同意认款 3 拒绝认款
        /// </summary>
        [DisplayName( "状态")]
        //[DataColumn(100, 60)]
        public int Status { set; get; }
        #endregion

        /// <summary>
        /// 签出记录
        /// </summary>
        public Guid CheckRecordID { get; set; }

        #region 方法
        /// <summary>
        /// 只有CSR本人可以修改
        /// 如没同意就可以修改
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool IsCanEdit(string user)
        {
            return this.Status != 2 && this.ApplyMan == user;
        }

        #endregion

    }

 }
